import test_exception_module
class HouseItem:
    """
    练习封装案例：家具信息类
    """
    def __init__(self, name, price, area):
        self.name = name
        self.price = price
        self.area = area

    def __str__(self):
        return (f'家具名称：{self.name},家具价格：{self.price},占地面积：{self.area}')

class House:
    """
    房屋类
    """
    def __init__(self,house_type,areas):
        self.house_type = house_type
        self.areas = areas
        self.free_area = areas
        self.items = []

    def __str__(self):
        return ("房屋类型：%s,房屋占地面积：%.2f,家具信息：%s,空余占地面积：%.2f"
                % (self.house_type, self.free_area, self.items, self.free_area))

    def add_item(self,item: HouseItem):
        if item.area>self.free_area:
            print('房间已满，无法添加家具')
        else:
            self.items.append(item.name)
            self.free_area -= item.area
            print(f'添加{item.name}成功')


class HouseManager:
    """
    练习私有属性和私有方法
    """
    def __init__(self,name,age):
        self.name = name
        self.__age = age

    def __hidden(self):
        print(f'姓名：{self.name},年龄：{self.__age}')
    def Customer(self):
        self.__hidden()

class employee:

    def __init__(self,name):
        self.name = name

    def inter(self):
        print('欢迎光临')
    def out(self):
        print('再见')


class saler(employee):
    def __init__(self,name,position):
        super().__init__(name)
        self.position = position

    def sale(self):
        print(f'我是{self.name}，我是{self.position}，谢谢消费')


class transporter(saler):
    def __init__(self,name,position,age):
        super().__init__(name,position)
        self.age = age

    def transport(self):
        print(f'我是{self.name}，我{self.position}，今年{self.age}岁，去帮您拿货')
class A:
    def __init__(self):
        print('A类多重继承')
class B:
    def __init__(self):
        print('B类多重继承')
class C(A,B):
    def test(self):
        print('B类多重继承')

class singer(object):
    instance = None
    def __new__(cls, *args, **kwargs):
        if cls.instance is None:
            cls.instance = super().__new__(cls)
        return cls.instance

    def __init__(self,name):
        self.name = name

def use_exception():
    """
    通过try进行异常捕捉，确保输入的内容一定是一个整型数，
    然后判断该整型数是否是对称数，12321就是对称数，
    123321也是对称数，否则就打印不是，非整型抛异常，不是对称数抛异常
    :return:
    """
    try:
        num = int(input('请输入一个整型数：'))
        if str(num) == str(num)[::-1]:
            print(f'{num}是对称数')
        else:
            print(f'{num}不是对称数')
    except ValueError:
        print('输入内容不是整型数')


if __name__ == '__main__':
    # 建立房屋
    house = House('三室两厅', 200)
    # 创建家具
    sofa = HouseItem('沙发', 1000, 50)
    bed = HouseItem('床', 500, 20)
    guizi = HouseItem('柜子', 300, 10)
    # 添加家具
    house.add_item(sofa)
    house.add_item(bed)
    house.add_item(guizi)
    print(house)
    print('-'*50)
    # 私有属性和私有方法
    xiaobai = HouseManager('小白', 25)
    xiaobai.Customer()
    print('-'*50)
    #练习单继承，多重继承案例
    xiaoming = employee('小明')
    xiaoming.inter()
    xiaoming.out()
    xiaohong = saler('小红','销售')
    xiaohong.sale()
    xiaohuang = transporter('小黄','运输',25)
    xiaohuang.transport()
    print('-'*50)
    #实现多重继承案例
    c = C()
    c.test()
    print(C.__mro__)
    print('-'*50)
    #实现单例模式
    singer1 = singer('周杰伦')
    singer2 = singer('刘德华')
    print(singer1.name)
    print(singer2.name)
    print('-'*50)
    #异常捕捉
    use_exception()